'''
Created on 13 juin 2013

@author: Nils Amiet
'''

from ITInfluence.models import Tweet

def getAllHashtags():
    tweets = Tweet.objects.all().exclude(hashtags="")
    hashtags = {}
    
    for tweet in tweets:
        currentTweetHashtags = tweet.hashtags.split(" ")
        for tag in currentTweetHashtags:
            try:
                hashtags[tag] += 1
            except KeyError:
                hashtags[tag] = 1
    
    hashtags = [(x,y) for x, y in hashtags.items()]
    return hashtags

def getSimilarHashtags(hashtag):
    similarHashtags = {}
    
    tweets = Tweet.objects.all().exclude(hashtags="").filter(hashtags__contains=hashtag)
    
    for tweet in tweets:
        currentTweetHashtags = tweet.hashtags.split(" ")
        try:
            currentTweetHashtags.remove(hashtag)
        except:
            pass
        for tag in currentTweetHashtags:
            try:
                similarHashtags[tag] += 1
            except KeyError:
                similarHashtags[tag] = 1
    
    similarHashtags = [(x,y) for x, y in similarHashtags.items()]
    return similarHashtags